package org.jivesoftware.smack.util;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

public class ObservableWriter extends Writer
{
  Writer wrappedWriter = null;
  List<WriterListener> listeners = new ArrayList();

  public ObservableWriter(Writer paramWriter)
  {
    this.wrappedWriter = paramWriter;
  }

  public void write(char[] paramArrayOfChar, int paramInt1, int paramInt2)
    throws IOException
  {
    this.wrappedWriter.write(paramArrayOfChar, paramInt1, paramInt2);
    String str = new String(paramArrayOfChar, paramInt1, paramInt2);
    notifyListeners(str);
  }

  public void flush()
    throws IOException
  {
    this.wrappedWriter.flush();
  }

  public void close()
    throws IOException
  {
    this.wrappedWriter.close();
  }

  public void write(int paramInt)
    throws IOException
  {
    this.wrappedWriter.write(paramInt);
  }

  public void write(char[] paramArrayOfChar)
    throws IOException
  {
    this.wrappedWriter.write(paramArrayOfChar);
    String str = new String(paramArrayOfChar);
    notifyListeners(str);
  }

  public void write(String paramString)
    throws IOException
  {
    this.wrappedWriter.write(paramString);
    notifyListeners(paramString);
  }

  public void write(String paramString, int paramInt1, int paramInt2)
    throws IOException
  {
    this.wrappedWriter.write(paramString, paramInt1, paramInt2);
    paramString = paramString.substring(paramInt1, paramInt1 + paramInt2);
    notifyListeners(paramString);
  }

  private void notifyListeners(String paramString)
  {
    WriterListener[] arrayOfWriterListener = null;
    synchronized (this.listeners)
    {
      arrayOfWriterListener = new WriterListener[this.listeners.size()];
      this.listeners.toArray(arrayOfWriterListener);
    }
    for (int i = 0; i < arrayOfWriterListener.length; i++)
      arrayOfWriterListener[i].write(paramString);
  }

  public void addWriterListener(WriterListener paramWriterListener)
  {
    if (paramWriterListener == null)
      return;
    synchronized (this.listeners)
    {
      if (!this.listeners.contains(paramWriterListener))
        this.listeners.add(paramWriterListener);
    }
  }

  public void removeWriterListener(WriterListener paramWriterListener)
  {
    synchronized (this.listeners)
    {
      this.listeners.remove(paramWriterListener);
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.util.ObservableWriter
 * JD-Core Version:    0.6.1
 */